select top 10 * from loja_saidas 
select top 10 * from faturamento_imagem 
select top 10 * from loja_nota_fiscal

SELECT *
from loja_saidas a
where substring(filial_DESTINO,1,3) = '525'
and TIPO_ENTRADA_SAIDA = '01'
and (
(substring(filial,1,3) = '128' and cast(numero_nf_transferencia as int) in (711,713)) or 
(substring(filial,1,3) = '124' and cast(numero_nf_transferencia as int) in (743,742,745,741,752,753,746,748,750,751,744,756,759,760,757,761,758)) or 
(substring(filial,1,3) = '095' and cast(numero_nf_transferencia as int) in (1069,1070,1068)) or 
(substring(filial,1,3) = '999' and rtrim(ltrim(numero_nf_transferencia)) = '280218'))
order by filial,numero_nf_transferencia

SELECT A.*
FROM faturamento_imagem A
JOIN loja_saidas B ON (A.NUMERO_FISCAL = B.numero_nf_transferencia AND A.FILIAL = B.filial and a.serie_nf = b.serie_nf)
where substring(B.filial_DESTINO,1,3) = '525'
and B.TIPO_ENTRADA_SAIDA = '01'
and (
(substring(B.filial,1,3) = '128' and cast(B.numero_nf_transferencia as int) in (711,713)) or 
(substring(B.filial,1,3) = '124' and cast(B.numero_nf_transferencia as int) in (743,742,745,741,752,753,746,748,750,751,744,756,759,760,757,761,758)) or 
(substring(B.filial,1,3) = '095' and cast(B.numero_nf_transferencia as int) in (1069,1070,1068)) or 
(substring(B.filial,1,3) = '999' and rtrim(ltrim(B.numero_nf_transferencia)) = '280218'))
order by B.filial,B.numero_nf_transferencia


select top 10 * from loja_nota_fiscal
